// 6. 异构计算设备抽象
// 设备特性元编程
template<typename DeviceT>
struct DeviceTraits;

// CPU特化
template<>
struct DeviceTraits<CPUDevice> {
    static constexpr bool supportsDouble = true;
    static constexpr bool supportsHalf = false;
    static constexpr int maxThreads = 64;
    
    template<typename T>
    using OptimalType = typename std::conditional<
        std::is_floating_point<T>::value,
        double,
        T
    >::type;
};

// GPU特化
template<>
struct DeviceTraits<GPUDevice> {
    static constexpr bool supportsDouble = true;
    static constexpr bool supportsHalf = true;
    static constexpr int maxThreads = 1024;
    
    template<typename T>
    using OptimalType = typename std::conditional<
        std::is_floating_point<T>::value,
        float,
        T
    >::type;
};

// 使用特性选择最优实现
template<typename DeviceT, typename T>
void process_image(DeviceT device, Image<T>& image) {
    using OptimalT = typename DeviceTraits<DeviceT>::template OptimalType<T>;
    
    // 根据设备特性选择最优实现
    if constexpr (DeviceTraits<DeviceT>::maxThreads > 128) {
        // 高并行实现
        parallel_process<OptimalT>(device, image);
    } else {
        // 低并行实现
        sequential_process<OptimalT>(device, image);
    }
}
